let ResponseUtils = require("../utils/ResponseUtils");
let {FormId,WechatUser} = require('../models');
let FormIdService = require("../service/formid");
let WechatService = require("../service/wechat");

/**
 * formid控制器
 */
class FormIdController {

    static async sendCourseOrderMsg(ctx) {
        let currentUser=ctx.currentUser;
        let body=ctx.request.body;
        let data = await FormIdService.checkOrderData(body);
        let token=await WechatService.getAccessToken();
        data.token=token;
        data.openId=currentUser.openId;
        let result = await FormIdService.sendCourseOrderMsg(data);
        ctx.body = ResponseUtils.builder(result).success().build();
    }
    static async findCourseEnd(ctx) {
        let result = await FormIdService.findCourseEnd();

        ctx.body = ResponseUtils.builder(result).success().build();
    }
    static async create(ctx){
        let body=ctx.request.body;
        let result = await FormIdService.create(body,ctx.currentUser);
        ctx.body = ResponseUtils.builder(result).success().build();
    }
}

module.exports = FormIdController;
